define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'worker_info/index' + location.search,
                    add_url: 'worker_info/add',
                    edit_url: 'worker_info/edit',
                    del_url: 'worker_info/del',
                    multi_url: 'worker_info/multi',
                    table: 'worker_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name')},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'gender', title: __('Gender')},
                        {field: 'age', title: __('Age')},
                        {field: 'mobile', title:'联系电话(非登陆账号)'},
                        {field: 'address', title: __('Address')},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pzy_status', title: __('Pzy_status'), searchList: {'normal':'正常','trash':'停用','deleted':'已删除','reviewing':'审核中','refused':'审核拒绝','unpaid':'未缴纳保证金','none':'未申请'}, formatter: Table.api.formatter.status},
                        {field: 'phy_status', title: __('Phy_status'), searchList: {'normal':'正常','trash':'停用','deleted':'已删除','reviewing':'审核中','refused':'审核拒绝','unpaid':'未缴纳保证金','none':'未申请'}, formatter: Table.api.formatter.status},
                        {field: 'user.is_spare', title: __('Status'), searchList: {'0':'跑单中','1':'空闲'}, formatter: Table.api.formatter.status},
                        {field: 'user.working_status', title: __('Status'), searchList: {'0':'下班','1':'上班'}, formatter: Table.api.formatter.status},
                        {field: 'deposit', title: '已付押金'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});